
package com.android.fitnesscenter.view.client;

import java.text.DecimalFormat;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.android.fitnesscenter.R;
import com.android.fitnesscenter.utils.ConfigProperties.TradingEntity;
import com.android.fitnesscenter.utils.ConfigProperties.TradingType;
import com.android.fitnesscenter.utils.MapEntity;
import com.android.fitnesscenter.utils.ToastHelper;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class ClientTopUpActivity extends ClientBaseActivity {

    @ViewInject(R.id.txt_yue_money)
    private TextView txt_yue_money;

    @ViewInject(R.id.txt_top_up_money)
    private TextView txt_top_up_money;

    @ViewInject(R.id.btn_ok)
    private TextView btn_ok;

    private MapEntity mMapEntity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.client_top_up_layout);
        ViewUtils.inject(this);
        initTitleBar(getString(R.string.txt_top_up));
        queryNewInfo(FROM_CLIENT_TOP_UP_ACTIVITY, TradingType.TOP_UP);
    }

    private void setCurrentInfo() {
        txt_top_up_money.setText(mMapEntity.getString(TradingEntity.MONEY));

        String yue = mMapEntity.getString(TradingEntity.YUE);
        if (!TextUtils.isEmpty(yue) && yue.contains(".")) {
            DecimalFormat df = new DecimalFormat("##0.00");
            double f = Double.parseDouble(yue);
            yue = df.format(f);
        } else if (TextUtils.isEmpty(yue)) {
            yue = "0";
        }
        txt_yue_money.setText(String.format(getString(R.string.txt_money_rmb), yue));
    }

    @Override
    protected void parseQueryNewInfoResult(int fromActivity, MapEntity entity) {
        if (entity != null && !entity.isEmpty()) {
            mMapEntity = entity;
            setCurrentInfo();
        } else {
            ToastHelper.getInstance().showShortMsg("暂无充值记录数据可确认!");
            finish();
        }
    }

    @Override
    protected void titlebarMethod(int id) {

    }

    @OnClick(R.id.btn_ok)
    public void btn_ok(View view) {
        updateMoney(FROM_CLIENT_TOP_UP_ACTIVITY, mMapEntity.getString(TradingEntity.ID));
    }

}
